//
//  SetPwdController.m
//  SafPay
//
//  Created by 贺庆博 on 2018/6/19.
//  Copyright © 2018年 ebo. All rights reserved.
//

#import "SetPwdController.h"
#import "CodeView.h"
#import "CopySafeWordController.h"
#import "SureSetPwdController.h"
@interface SetPwdController ()

@property (nonatomic,strong) TRRequest *request;
@property (nonatomic,copy) NSString *pwd;
@end

@implementation SetPwdController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"设置安全密码";
    [self initUI];
    
}

- (void)initUI
{
    

    [IQKeyboardManager sharedManager].enable = NO;
    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = NO;
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 10, kScreenWidth, 108)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    UILabel *lab = [UILabel labelWithFrame:CGRectMake(12, 20, kScreenWidth - 24, 14) font:kFONT(15) color:rgb(58,58,58) text:@"输入新密码"];
    lab.textAlignment = NSTextAlignmentCenter;
    [view addSubview:lab];
    lab.textAlignment = NSTextAlignmentCenter;
    CodeView *codeView = [[CodeView alloc] initWithFrame:CGRectMake(60, lab.yzBottom + 5, kScreenWidth - 120, (kScreenWidth - 120)/6)  num:6 lineColor:[UIColor blackColor] textFont:14];
    codeView.hasSpaceLine = NO;
    //输入风格
    codeView.codeType = CodeViewTypeCustom;
    codeView.hasUnderLine = YES;
    codeView.noInputAni = NO;
    codeView.codeType = CodeViewTypeSecret;
    [view addSubview:codeView];
    [codeView beginEdit];

    kWeakSelf(weakSelf);

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"下一步" forState:UIControlStateNormal];
    btn.titleLabel.font = kFONT(16);
    btn.backgroundColor = rgb(33,177,227);
    [self.view addSubview:btn];
    [[btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
//        CopySafeWordController *vc = [CopySafeWordController new];
//        [self.navigationController pushViewController:vc animated:YES];
     
        SureSetPwdController *vc=[SureSetPwdController new];
        vc.oldPwd=weakSelf.pwd;
        vc.isChange=weakSelf.isChange;
        vc.isSetting=weakSelf.isSetting;
        [weakSelf.navigationController pushViewController:vc animated:YES];
        
    }];
    codeView.EditingBlcok = ^(NSString *text) {
        
        if(text.length<6){
            
            [btn setUserInteractionEnabled:NO];
            [btn setBackgroundColor:kGrayColor];
        }else{
            
            [btn setUserInteractionEnabled:YES];
            [btn setBackgroundColor:rgb(33,177,227)];
        }
    };
    codeView.EndEditBlcok = ^(NSString *text) {
        
        weakSelf.pwd=text;
        SureSetPwdController *vc=[SureSetPwdController new];
        vc.oldPwd=weakSelf.pwd;
        vc.isChange=weakSelf.isChange;
        vc.isSetting=weakSelf.isSetting;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    };
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self.view);
        make.height.equalTo(@44);
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
